package indi.xielin.start.method;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

public class DeleteAllMethod extends AbstractMethod {
    private final String METHOD_NAME="deleteAll";
    /**
     * 清空表
     * @param mapperClass  mapper接口class
     * @param modelClass   mapper泛型class
     * @param tableInfo    表信息
     * @return
     * 这里@TableLogic不会生效。
     */
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo)  {
//        String sql="truncate table "+tableInfo.getTableName().toString();
        String sql="delete from "+tableInfo.getTableName().toString();
        SqlSource sqlSource = this.languageDriver.createSqlSource(configuration, sql, modelClass);//
        return this.addDeleteMappedStatement(mapperClass,METHOD_NAME,sqlSource);
    }
}
